<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>模板标签</title>
	<style type="text/css">
	
	ul {
		list-style: none;
		margin: 10px 0;
		border: 1px dotted #aaa;
	}

	li{
		widows: 300px;
		padding: 5px 0;
	}

    </style>
</head>
<body>
	<div class="container">
		<h1>模板标签</h1>
		<div id="box">
			
		</div>
	</div>
<script src="https://cdn.bootcss.com/decimal.js/10.2.0/decimal.min.js"></script>

<script src="https://cdn.staticfile.org/jquery/3.2.0/jquery.js"></script>
<script type="text/javascript">


let stus = ['小明', '张三', '王五', '爱情'];
// [0, stus.length) 刚好是数组索引的有效值
let pos = Math.floor(Math.random() * stus.length);
console.log(stus[pos]);

console.log('-----------------------\n')

/**
 * 随机取数组元 start(包含) - end(不包含)的数组元素
 */
function arrayRandom(arr, start, end) {
	start = start || 0
	end = end || arr.length
	if( (start < 0 || start > arr.length) || 
		(end < 0 || end > arr.length)  ) {
		throw new Error('数组可能越界');
	}

	let randIndex = Math.floor(Math.random() * (end - start)) + start
	return arr[randIndex];
}


arrayRandom(stus, 33)

for (var i = 0; i < 10000000; i++) {
	var randOne = arrayRandom(stus, 1, 3)
	if( randOne != '张三' && randOne != '王五') {
		console.log(randOne);
	}
}

</script>
</body>
</html>

